#pragma once
#include <string>
#include <memory> // std::auto_ptr
#include <cstdlib> // std::exit
#include <iostream>
#include <odb/database.hxx>
#include <odb/mysql/database.hxx>
#include "logger.hpp"

namespace zrb
{
    class ODBFactory
    {
    public:
        //最大连接池数量
        //用户名,密码,数据库名字，主机地址，端口号，字符集
        static std::shared_ptr<odb::core::database> create(
            long unsigned int max_pool,
            const std::string& user,
            const std::string& password,
            const std::string& dbname,
            const std::string& host,
            unsigned int port,
            const std::string& cset)
        {
            //1. 构造连接池工厂配置对象
            std::unique_ptr<odb::mysql::connection_pool_factory> cpf(
            new odb::mysql::connection_pool_factory(max_pool, 0));
            //2. 构造数据库操作对象
            auto db = std::make_shared<odb::mysql::database>(user,password,dbname,
                host,port,"",cset,0,std::move(cpf));
            return db;
        }
    };
}